import React, { useEffect, useState } from 'react'
import { ImageBackground, StyleSheet, Text, View } from 'react-native'
// import { View } from 'react-native-animatable'
import axios from '../../api/axios'
function format(){
    const dateTime = new Date()
    const year = dateTime.getFullYear()
    const month = dateTime.getMonth() + 1 > 9 ? dateTime.getMonth() + 1 : '0' + dateTime.getMonth()
    const day = dateTime.getDate() > 9 ? dateTime.getDate() : '0' + dateTime.getDate()
    return `${year}-${month}-${day}`
}
const Sign = () => {
    const [data, setData] = useState({})

    useEffect(()=>{
        // console.log(format());
        let now = format()
        console.log(now);
        console.log(1);
        let date = new Date()

        //获取当前时间，格式类似'2023-02-23 15:58:05'
        let year = date.getFullYear()
        let month = (date.getMonth() + 1).toString().padStart(2,'0')
        let day = date.getDate().toString().padStart(2,'0')
        
        let str = `${year}-${month}-${day}`
        
        axios({
            method: 'GET',
            url: 'https://apis.juhe.cn/fapig/birthdayFlower/query?key=642c9d3324cacaed25eaee6d5ad18d2e&keyword='+str,
            // url: 'http://apis.juhe.cn/fapig/birthdayFlower/query?key='+'642c9d3324cacaed25eaee6d5ad18d2e'+ '&keyword='+now,
            // url: "http://apis.juhe.cn/fapig/birthdayFlower/query",
            // data: {key: '642c9d3324cacaed25eaee6d5ad18d2e', keyword: now},  
        })
            .then(function (res) {
                console.log(res);
                    setData(res.result)
                    if(res.reson == "SUCCES"){
                    setData(res.result)
                    console.log(res.result);
                }
            });
    },[])
  return (
    <ImageBackground source={require('../../../images/mine/signbg.jpg')} style={{height: '100%', alignItems:'center', paddingTop: '5%'}}>
        <View style={{width: '90%'}}>
            <Text style={styles.textB}>今日：{data.birthday?data.birthday: ''}</Text>
            <Text style={styles.textB}>今日象征：{data.birthday?data.name: ''}</Text>
        </View>
        <View style={{width: '90%'}}>
            <Text>含义</Text>
            <Text style={{fontSize: 13,letterSpacing: 1,lineHeight: 18, marginTop: '2%'}}>
                {data.birthday?data.name_des.replace(/<p>/, '').replace(/<\/p>/, ''): ''}
            </Text>
        </View>
        <View style={{width: '90%', marginTop: '12%'}}>
            <Text style={styles.textB}>生日花语：{data.birthday?data.lang: ''}</Text>
        </View>
        <View style={{width: '90%'}}>
            <Text style={{fontSize: 13,letterSpacing: 1, lineHeight: 18}}>
            {data.birthday?data.lang_des.replace(/<p>/, '').replace(/<\/p>/, ''): ''}
            </Text>
        </View>
    </ImageBackground>
  )
}
const styles = StyleSheet.create({
    textB: {
        fontSize: 15,
        marginBottom: 5
    }
  });
export default Sign